import { configureStore } from '@reduxjs/toolkit';
import logger from 'redux-logger';
import themeSlice, { THEME_FEATURE_KEY } from "./slices/theme";
import wallpaperTypeSlice, { WALLPAPERTYPE_FEATURE_KEY } from './slices/wallpaperTypes';
import { wallpaperApi } from '@services/wallpaper';

const store = configureStore({
  devTools: process.env.NODE_ENV !== 'production',
  reducer: { // 这里传入的 reducer 就是 combineReducer
    [THEME_FEATURE_KEY]: themeSlice,
    [WALLPAPERTYPE_FEATURE_KEY]: wallpaperTypeSlice,
    [wallpaperApi.reducerPath]: wallpaperApi.reducer,
  },
  // 把内置的中间件和新的中间件连接起来
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware().concat(logger, wallpaperApi.middleware),
})

export type RootState = ReturnType<typeof store.getState>;

export type AppDispatch = typeof store.dispatch;

export default store;
